import {
  SEARCH_BLUR,
  SEARCH_FOCUS,
  CHANGE_LIST,
  ON_MOUSE_ENTER,
  ON_MOUSE_LEAVE,
  ON_CHANGE_PAGE
} from "./types";
import { fromJS } from "immutable";
import axios from "axios";
const changeList = data => ({
  type: CHANGE_LIST,
  data: fromJS(data),
  totalPage: Math.ceil(data.length / 10)
});
export const searchFocus = () => ({
  type: SEARCH_FOCUS
});
export const searchBlur = () => ({
  type: SEARCH_BLUR
});
export const onMouseEnter = () => ({
  type: ON_MOUSE_ENTER
});
export const onMouseLeave = () => ({
  type: ON_MOUSE_LEAVE
});

export const onChangePage = (page) => ({
  type: ON_CHANGE_PAGE,
  page
});


export const getList = () => {
  return dispatch => {
    axios
      .get("/api/headerList.json")
      .then(res => {
        const data = res.data;
        dispatch(changeList(data.data));
      })
      .catch(err => {
        console.log(err);
      });
  };
};
